##################################################################################
##################################################################################
##################################################################################
##################################################################################
##################################################################################

require(lattice)
require(MASS)
require(foreign)

##################################################################################

### Figure 1 ###

# Read in "Means.csv" and assign it to an object titled "means1"

means1$item <- factor(means1$item,levels(means1$item)[c(1,3,5,2,8)])
droplevels(means1$item)

dotplot(as.factor(item) ~ reps, 
        data = means1,
        aspect = 1.5, 
        xlab = "Proportion",
        ylab = "",
        pch = 17,
        xlim = c(-.05, .725),
        key=list(columns=1,points=list(pch=c(17,16), col=c("red","blue")),
                 text=list(c("Republican", "Democrat"))),
        panel = function(...) {
          panel.dotplot(..., lty = 2)
          panel.xyplot(means1$reps, means1$item, col = "red", pch = 17)
          panel.xyplot(means1$dems, means1$item, col = "blue", pch = 16)
          panel.segments(means1$lowerr, as.numeric(means1$item),
                         means1$upperr, as.numeric(means1$item), col = "red")
          panel.segments(means1$lowerd, as.numeric(means1$item),
                         means1$upperd, as.numeric(means1$item), col = "blue")
        }
)



### Figure A1, Supplemental Appendix ###

# Read in "Means.csv" and assign it to an object titled "means2"

means2$item <- factor(means2$item,levels(means2$item)[c(9,3,1,7,4,6,5,8,2)])

dotplot(as.factor(item) ~ reps, 
        data = means2,
        aspect = 1.5, 
        xlab = "Proportion",
        ylab = "",
        pch = 17,
        xlim = c(-.05, .725),
        key=list(columns=1,points=list(pch=c(17,16), col=c("red","blue")),
                 text=list(c("Republican", "Democrat"))),
        panel = function(...) {
          panel.dotplot(..., lty = 2)
          panel.xyplot(means2$reps, means2$item, col = "red", pch = 17)
          panel.xyplot(means2$dems, means2$item, col = "blue", pch = 16)
          panel.segments(means2$lowerr, as.numeric(means2$item),
                         means2$upperr, as.numeric(means2$item), col = "red")
          panel.segments(means2$lowerd, as.numeric(means2$item),
                         means2$upperd, as.numeric(means2$item), col = "blue")
        }
)




